package com.yilin.tms.user.controller;


import com.yilin.tms.core.application.ReturnData;
import com.yilin.tms.core.commons.annotation.SkipGateway;
import com.yilin.tms.core.commons.base.BaseController;
import com.yilin.tms.core.commons.annotation.NotNull;
import com.yilin.tms.core.entity.user.account.Contact;
import com.yilin.tms.user.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/contacts/")
public class ContactsController extends BaseController {

    @Autowired
    private IAccountService accountService;

    /**
     * 获取联系人
     */
    @PostMapping(value = "getContactsList")
    @NotNull({"contactsType"})
    public ReturnData<List<Contact>> getContactsList(Contact query) {
        List<Contact> list = accountService.getContactsList(getLoginUser().getId(), query);
        return jsonView(SUCCESS_CODE, "获取成功", list);
    }

    /**
     * 添加编辑联系人
     */
    @PostMapping(value = "saveContacts")
    @NotNull({"contactsType", "name", "mobile", "address"})
    public ReturnData<Object> saveContacts(Contact contact) {
        contact.setAccountId(getLoginUser().getId());
        accountService.saveContacts(contact);
        return jsonView(SUCCESS_CODE, "保存成功");
    }
    /**
     * 根据ID获取联系人
     */
    @PostMapping(value = "getContactById")
    @NotNull({"contactId"})
    public ReturnData<Object> getContactById(String contactId) {
        return jsonView(SUCCESS_CODE, "保存成功",  accountService.getContactById(contactId));
    }

    /**
     * 删除联系人（真实删除）
     */
    @PostMapping(value = "deleteContacts")
    @NotNull({"id"})
    public ReturnData<Object> deleteContacts(Contact contact) {
        accountService.deleteContacts(contact);
        return jsonView(SUCCESS_CODE, "删除成功");
    }
    /**
     *
     */
    @PostMapping(value = "test001")
    @SkipGateway
    public ReturnData<Object> test001(String organize01,String organize02,String organizeName) {
        accountService.test002(organize01,organize02,organizeName);

        return jsonView(true, "操作成功");
    }
}
